<!-- CommentInput.vue -->
<template>
  <div class="comment-input">
    <textarea
      v-model="content"
      :placeholder="placeholder"
      rows="3"
      @keydown.enter="submitIfShiftNotPressed($event)"
    ></textarea>
    <div class="actions">
      <button @click="submitComment">发布评论</button>
    </div>
  </div>
</template>

<script setup>
import { ref, defineProps, defineEmits } from 'vue';

const props = defineProps({
  placeholder: {
    type: String,
    default: '请输入评论...'
  }
});

const emit = defineEmits(['submit']);
const content = ref('');

const submitComment = () => {
  if (content.value.trim()) {
    emit('submit', content.value.trim());
    content.value = '';
  }
};

const submitIfShiftNotPressed = (event) => {
  if (event.key === 'Enter' && !event.shiftKey) {
    event.preventDefault();
    submitComment();
  }
};
</script>

<style scoped>
.comment-input {
  margin-bottom: 20px;
}
textarea {
  width: 100%;
  padding: 10px;
  border: 1px solid #ddd;
  border-radius: 4px;
  resize: vertical;
}
.actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 10px;
}
button {
  padding: 8px 16px;
  background-color: #4CAF50;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}
button:hover {
  background-color: #45a049;
}
</style>